import '../../../utils/json_converter.dart';

class BookSalesReq {
  String? storeId;
  String? bookId; // 单本出售不能为空
  String? packageId; // 套装出售不能为空
  String? name; // 单本出售不能为空
  int quantity;
  int payType;
  double? salePrice; // 销售价格

  BookSalesReq({
    required this.storeId,
    this.bookId,
    this.packageId,
    this.name,
    required this.quantity,
    required this.payType,
    this.salePrice,
  });

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['storeId'] = storeId;
    data['packageId'] = packageId;
    data['bookId'] = bookId;
    data['name'] = name;
    data['quantity'] = quantity;
    data['payType'] = payType;
    data['salePrice'] = salePrice;
    return data;
  }

  factory BookSalesReq.fromJson(Map<String, dynamic> json) {
    return BookSalesReq(
      storeId: JsonConverter.toStr(json['storeId']),
      packageId: JsonConverter.toStr(json['packageId']),
      bookId: JsonConverter.toStr(json['bookId']),
      name: JsonConverter.toStr(json['name']),
      quantity: JsonConverter.toIntWithDefault(json['quantity']),
      payType: JsonConverter.toIntWithDefault(json['payType']),
      salePrice: JsonConverter.toDouble(json['salePrice']),
    );
  }
}
